
package net.altran.tests.embedded.cdi_ejb_jpa;

//Simple TestBean to test CDI. 
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

//This bean implements Serializable as it needs to be placed into a Stateful Bean
@Stateless
public class TestBean {
    @PersistenceContext()
    private EntityManager em;

    public void addPerson(String name) {
        Person p = new Person();
        p.setName(name);
        em.persist(p);
    }

    public Person getPerson(Long pid) {
        return em.find(Person.class, pid);
    }

    public void removePerson(Long pid) {
        Person p = getPerson(pid);
        if(p != null) {
            em.remove(p);
        }
    }

    public void removePerson(Person p) {
        em.remove(p);
    }
}
